package io.ext;

import org.apache.dubbo.rpc.AsyncContext;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.stereotype.Service;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CompletableFuture;

import io.ext.dubbo.SomeService;

@Service("someService")
public class SomeServiceImpl implements SomeService
{
    Timer timer = new Timer();
    @Override
    public CompletableFuture<String> foo() {
        CompletableFuture<String> f = new CompletableFuture<>();
        timer.schedule(new TimerTask()
        {
            @Override
            public void run() {
                f.complete("fuck");
            }
        },1000);
        return f;
    }

    @Override
    public String foo1() {
        AsyncContext asyncContext = RpcContext.startAsync();
        timer.schedule(new TimerTask()
        {
            @Override
            public void run() {
                asyncContext.write(new RuntimeException());
            }
        },1000);
        return null;
    }
}
